const express = require("express");
const router = express.Router();

const MySql = require("./../lib/mysql");

router.post("/userRegister",async(req,res,next) => {
try {
    //从前端得到的表单内容传到后台
    const id = req.body.id;
    const name = req.body.name; //真实姓名
    const sex = req.body.sex;
    const password = req.body.password;
    const phone = req.body.phone;
    const email = req.body.email;
    const specialty = req.body.specialty;
    const college = req.body.college;
    const photourl = req.body.photourl;
    const birthday = req.body.birthday;
    const homeland = req.body.homeland;
    const politic = req.body.politic;
    const nationality = req.body.nationality;

   console.log(id,name,sex,password,phone,email,specialty,college,photourl,birthday,homeland,politic,nationality);

    //数据库操作
    // const res1 = await MySql.query('select * from user',[]);
    // console.log(res1);
    const res2 = await MySql.query('insert user(id,name,sex,password,phone,email,specialty,college,photourl,birthday,homeland,politic,nationality) values (?,?,?,?,?,?,?,?,?,?,?,?,?)',[id,name,sex,password,phone,email,specialty,college,photourl,birthday,homeland,politic,nationality]);

    res.json({
        code:1,
        message:'保存成功'
    })

} catch (error) {
    console.log(error)
    res.json({
        code: -1,
        message: '服务器错误'
    })
}
    
});

module.exports = router;